package com.clean.scanlibrary.adapter

import android.content.Context
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import oa.lla.cca.R
import com.clean.scanlibrary.bean.DiscernInfoBean
import oa.lla.cca.databinding.DiscernItemLayoutBinding
import java.math.BigDecimal

class DiscernTipsAdapter(val context: Context, val dataList:ArrayList<DiscernInfoBean>):
    RecyclerView.Adapter<DiscernTipsAdapter.Holder>() {


    class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) {

    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
        val inflate =
            LayoutInflater.from(context).inflate(R.layout.discern_item_layout, parent, false)
        return Holder(inflate)
    }

    override fun onBindViewHolder(holder: Holder, position: Int) {
        dataList.get(position).apply {
            if (!TextUtils.isEmpty(score)) {
                val decimal: BigDecimal = BigDecimal(score)
                val toDouble = decimal.setScale(2, BigDecimal.ROUND_HALF_UP).toDouble()
                val customDecimal = toDouble * 100
                holder.itemView.findViewById<TextView>(R.id.item_score).visibility = View.VISIBLE
                holder.itemView.findViewById<TextView>(R.id.item_score).text =
                    "相似度：${customDecimal}%"
            } else {
                holder.itemView.findViewById<TextView>(R.id.item_score).visibility = View.GONE
            }

            holder.itemView.findViewById<TextView>(R.id.item_name).text = "相似物：${name}"
//                if (baike_info!=null && !TextUtils.isEmpty(baike_info.description)){
//                    itemDec.visibility = View.VISIBLE
//                    itemDec.text = baike_info.description
//                }else{
//                    itemDec.visibility = View.GONE
//                }

        }

    }

    override fun getItemCount(): Int {
        return if (dataList != null && dataList.size > 0) {
            return dataList.size
        } else {
            0
        }
    }
}